﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace SistemasBuenosAires.Website.Controls
{
    public partial class ContactForm : System.Web.UI.UserControl
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            Initialize();
        }

        #region PROPERTIES
        //Asignar Textbox

        public String Name { get; set; }

        public String Surname { get; set; }

        public String Company { get; set; }

        public String Email { get; set; }

        public int PhoneCode { get; set; }

        public int PhonePrefix { get; set; }

        public int PhoneSuffix { get; set; }

        public String Subject { get; set; }

        public String Message { get; set; }

        #endregion

        protected void Initialize()
        {
            RegisterScript();

        }

        public void ClearForm()
        {
            TextBoxName.Text = String.Empty;
            TextBoxSurname.Text = String.Empty;
            TextBoxCompany.Text = String.Empty;
            TextBoxEmail.Text = String.Empty;
            TextBoxPhone.Text = String.Empty;
            TextBoxSubject.Text = String.Empty;
            TextBoxMessage.Text = String.Empty;
            MessageSended.Style.Add("display", "none");
            CheckFields.Style.Add("display", "none");
        }

        protected void RegisterScript()
        {
            String script;
            var streamReader = new StreamReader(Request.PhysicalApplicationPath + "/Controls/ContactForm/ContactForm.js");
            streamReader.ReadLine();
            streamReader.ReadLine();
            script = streamReader.ReadToEnd();

            var clientScript = Page.ClientScript;
            if(!clientScript.IsStartupScriptRegistered("ContactFormScript"))
            {
                clientScript.RegisterStartupScript(this.GetType(),"ContactFormScript",script,true);
            }
        }

        protected void ShowMessageSended()
        {
            MessageSended.Style.Add("display", "");
        }

        public event System.EventHandler SendRequest;

        protected void ButtonSend_Click(object sender, EventArgs e)
        {
            if (SendRequest != null)
            {
                ShowMessageSended();
                SendRequest(sender, e);
            }
        }

    }
}